<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDefinitionFileSchema">

<Version>
    <Major>1</Major>
    <Minor>0</Minor>
    <Build>1</Build>
    <Revision>0</Revision>
</Version>
<EventClasses>
    <EventClass>
        <EventClassName>OrdersE</EventClassName>
        <Schema>
            <Field>
                <FieldName>OrderID</FieldName>
                <FieldType>int</FieldType>
                <FieldTypeMods>not null</FieldTypeMods>
            </Field>
            <Field>
                <FieldName>Item</FieldName>
                <FieldType>varchar(100)</FieldType>
            </Field>
            <Field>
                <FieldName>Quantity</FieldName>
                <FieldType>int</FieldType>
            </Field>
            <Field>
                <FieldName>Department</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
            <Field>
                <FieldName>PaymentStatus</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
        </Schema>
        <IndexSqlSchema>
            <SqlStatement>CREATE INDEX DepartmentIndex ON OrdersE ( Department ) </SqlStatement>
            <SqlStatement>CREATE INDEX PaymentStatusIndex ON OrdersE ( PaymentStatus ) </SqlStatement>
        </IndexSqlSchema>
    </EventClass>
</EventClasses>

<SubscriptionClasses>
    <SubscriptionClass>
        <SubscriptionClassName>OrdersS</SubscriptionClassName>
        <Schema>
            <Field>
                <FieldName>DeviceName</FieldName>
                <FieldType>nvarchar(255)</FieldType>
                <FieldTypeMods>not null</FieldTypeMods>
            </Field>
            <Field>
                <FieldName>SubscriberLocale</FieldName>
                <FieldType>nvarchar(10)</FieldType>
                <FieldTypeMods>not null</FieldTypeMods>
            </Field>
            <Field>
                <FieldName>Department</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
            <Field>
                <FieldName>PaymentStatus</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
        </Schema>
        <EventRules>
            <EventRule>
                <RuleName>OrderEntrySubscriptionsEventRule</RuleName>
                <Action>
                           SELECT dbo.OrdersNNotify(
                               s.SubscriberId, s.DeviceName, s.SubscriberLocale,
                               e.OrderID, e.Item, e.Quantity, 
                               e.Department, e.PaymentStatus)
                           FROM OrdersE e INNER JOIN OrdersS s
                           ON e.Department = s.Department
                           WHERE LEFT(e.PaymentStatus, 1) = s.PaymentStatus
                </Action>
                <EventClassName>OrdersE</EventClassName>
            </EventRule>
        </EventRules>
    </SubscriptionClass>
</SubscriptionClasses>

<NotificationClasses>
    <NotificationClass>
        <NotificationClassName>OrdersN</NotificationClassName>
        <Schema>
            <Fields>
            <Field>
                <FieldName>OrderID</FieldName>
                <FieldType>int</FieldType>
            </Field>
            <Field>
                <FieldName>Item</FieldName>
                <FieldType>varchar(100)</FieldType>
            </Field>
            <Field>
                <FieldName>Quantity</FieldName>
                <FieldType>int</FieldType>
            </Field>
            <Field>
                <FieldName>Department</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
            <Field>
                <FieldName>PaymentStatus</FieldName>
                <FieldType>char(3)</FieldType>
            </Field>
            </Fields>
        </Schema>
        <ContentFormatter>
            <ClassName>XsltFormatter</ClassName>
            <Arguments>
                <Argument>
                    <Name>XsltBaseDirectoryPath</Name>
                    <Value>%_BaseDirectoryPath_%</Value>
                </Argument>
                <Argument>
                    <Name>XsltFileName</Name>
                    <Value>OrderEntry.xslt</Value>
                </Argument>
            </Arguments>
        </ContentFormatter>

        <Protocols>
            <Protocol>
                <ProtocolName>File</ProtocolName>
            </Protocol>
            <Protocol>
                <ProtocolName>SMTP</ProtocolName>
                <Fields>
                    <Field>
                        <FieldName>Subject</FieldName>
                        <SqlExpression>'Order Entry Notification'</SqlExpression>
                    </Field>
                    <Field>
                        <FieldName>BodyFormat</FieldName>
                        <SqlExpression>'html'</SqlExpression>
                    </Field>
                    <Field>
                        <FieldName>From</FieldName>
                        <SqlExpression>'OrderEntryNotificationService@mycompany.com'</SqlExpression>
                    </Field>
                    <Field>
                        <FieldName>Priority</FieldName>
                        <SqlExpression>'Normal'</SqlExpression>
                    </Field>
                    <Field>
                        <FieldName>To</FieldName>
                        <SqlExpression>DeviceAddress</SqlExpression>
                    </Field>
                </Fields>

                    <!-- Custom Protocol execution parameters omitted for now
                    <ProtocolExecutionSettings>
                    </ProtocolExecutionSettings>
                    -->
            </Protocol>
        </Protocols>

        <ExpirationAge>PT2H</ExpirationAge>
    </NotificationClass>
</NotificationClasses>

<Providers>
    <NonHostedProvider>
        <ProviderName>EventCreator</ProviderName>
    </NonHostedProvider>
</Providers>

<Generator>
    <SystemName>%_NSSystem_%</SystemName>
</Generator>

<Distributors>
    <Distributor>
        <SystemName>%_NSSystem_%</SystemName>
    </Distributor>
</Distributors>

<ApplicationExecutionSettings>
    <QuantumDuration>P0DT0H0M30S</QuantumDuration>
    <ChronicleQuantumLimit>0</ChronicleQuantumLimit>
    <SubscriptionQuantumLimit>0</SubscriptionQuantumLimit>
    <ProcessEventsInOrder>true</ProcessEventsInOrder>
</ApplicationExecutionSettings>

</Application>
